package com.ctgu.module.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ctgu.common.util.CoreConst;
import com.ctgu.module.admin.mapper.EmailMapper;
import com.ctgu.module.admin.mapper.UserMapper;
import com.ctgu.module.admin.model.Email;
import com.ctgu.module.admin.model.User;
import com.ctgu.module.admin.service.EmailService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;



@Service
@AllArgsConstructor
public class EmailServiceImpl extends ServiceImpl<EmailMapper, Email> implements EmailService {

    private final EmailMapper emailMapper;

    @Override
    public List<Email> selectAllEmailsByAddress(String address) {
        List<Email> emailList = emailMapper.selectList(Wrappers.<Email>lambdaQuery().eq(Email::getAddress, address));
        // 剔除已经删除掉了的数据，伪删除
        emailList.removeIf(email -> email.getStatus() < 0);
        return emailList;
    }

    @Override
    public Integer getEmailsNumberByUserID(Integer userID) {
        return emailMapper.getNumberOfEmailsByUserID(userID);
    }
}
